//登录相关接口

import type {
  LoginResult,
  LoginWXParams,
  PostLoginUserParams,
  TokenRefreshParams,
} from '@/types/login'
import { http } from '@/utils/http'

/**
 *小程序登录
 * @param data 请求参数
 * @returns
 */
export const postLoginWxMinAPI = (data: LoginWXParams) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/login/wxMin',
    data,
  })
}

/**
 * 小程序登录，内测版，通过手机号登录
 * @param data 登录手机号
 * @returns
 */
export const postLoginWxMinSimpleAPI = (phoneNumber: string) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/login/wxMin/simple',
    data: {
      phoneNumber,
    },
  })
}

/**
 * 传统登录：通过用户名/手机号 密码登录
 * @param data
 */
export const postLoginUserAPI = (data: PostLoginUserParams) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/login',
    data,
  })
}

export const loginRefreshAPI = (data: TokenRefreshParams) => {
  return http<LoginResult>({
    method: 'PUT',
    url: '/login/refresh',
    data,
  })
}
